//
//  UIScrollViewExt.swift
//  test-ios
//
//  Created by wyz5204 on 2023/6/6.
//

import Foundation
import UIKit
import MJRefresh

//MARK: UIScrollView
extension UIScrollView {
    /// 添加头部刷新
    func addHeaderRefresh(block: @escaping MJRefreshComponentAction) {
        let header = MJRefreshNormalHeader.init(refreshingBlock: block)
        self.mj_header = header
    }
    /// 添加脚部刷新（手动）
    func addFooterRefresh(block: @escaping MJRefreshComponentAction) {
        let footer = MJRefreshBackStateFooter.init(refreshingBlock: block)
        self.mj_footer = footer
    }
    /// 添加脚部刷新（自动）
    func addFooterAutoRefresh(block: @escaping MJRefreshComponentAction) {
        let footer = MJRefreshAutoStateFooter.init(refreshingBlock: block)
        footer.triggerAutomaticallyRefreshPercent = 0
        self.mj_footer = footer
    }
    
    //开启头部刷新
    func beginHeaderRefresh() {
        self.resetNoMoreData()
        self.mj_header?.beginRefreshing()
    }
    
    //结束头部刷新
    func endHeaderRefresh() {
        self.mj_header?.endRefreshing()
    }
    
    //开启脚部刷新
    func begingFooterRefresh() {
        self.mj_footer?.beginRefreshing()
    }
    
    //结束脚部刷新
    func endFooterRefresh() {
        self.mj_footer?.endRefreshing()
    }
    
    //没有更多数据
    func noMoreData() {
        self.mj_footer?.endRefreshingWithNoMoreData()
    }
    
    //重置noMore
    func resetNoMoreData() {
        self.mj_footer?.resetNoMoreData()
    }
    
    
}
